﻿(function () {

    layui.use(["layer", "jquery", "table", "form"], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        $(document).ready(function () {
            $("#btnSearch").click(function () {
                reloadTable();
            });
        });

        laydate.render({
            elem: '#txtSearchDate',
            value: (new Date()),
            isInitValue: true,
            showBottom: false
        });

        table.render({
            elem: "#AppointmentTable",
            url: "/Appointment/List",
            height: "full-68", // (10 + 38 + 10 + 10)
            page: false,
            method: "POST",
            where: getTableQueryParam(),
            even: true,
            totalRow: true,
            parseData: function (res) {
                //console.log(res);
                return {
                    "code": res.Success == true ? 0 : -1,
                    "msg": res.Msg,
                    "count": res.Total,
                    "data": res.Data,
                    "totalRow": {
                        "count": res.Total
                    }
                };
            },
            cols: [[
                {
                    type: 'numbers', title: 'No.', width: 60, fixed: 'center'
                    , totalRow: '{{= d.TOTAL_ROW.count }}'
                }
                , { field: "Name", width: 140, align: "center", title: "预约人" }
                , { field: "InvitationCode", width: 160, align: "center", title: "预约人邀请码" }
                , { field: "Phone", width: 120, align: "center", title: "手机号码" }
                , { field: "Type", width: 120, align: "center", title: "预约类型" }
                , { field: "Time", align: "center", title: "预约时间" }
            ]]
        });

        function getTableQueryParam() {
            return {
                Date: $("#txtSearchDate").val().trim(),
                Name: $("#txtSearchName").val().trim(),
                Type: ""
            };
        }

        function reloadTable() {
            table.reloadData("AppointmentTable", {
                where: getTableQueryParam()
            });
        }
    });

})();